<?php

declare(strict_types=1);

namespace App\Model\Orders;

use App\Model\Model;
use App\Traits\Model\Orders\Order as OrderTraits;
use Hyperf\Snowflake\Concern\Snowflake;

/**
 * @property string $id
 * @property int $user_id 用户ID
 * @property int $shop_id 店铺ID
 * @property int $app_id 应用ID
 * @property string $no 订单号码
 * @property string $merchant_no 商家单号
 * @property string $paid_no 支付单号
 * @property string $transaction_id 支付流水号
 * @property string $consignee 收货人姓名
 * @property string $address 收货人详细地址
 * @property string $mobile 收货人手机号码
 * @property string $prov 收货省
 * @property string $city 收货市
 * @property string $area 收货区
 * @property string $shipping_at 发货时间
 * @property float $paid_amount 实际支付金额
 * @property string $total_amount 总金额
 * @property string $postage_amount 邮费
 * @property array $discount_amount 折扣金额
 * @property string $time_expire 订单结束时间
 * @property string $confirm_at 确认收货时间
 * @property string $complete_at 完成时间
 * @property string $paid_at 支付时间
 * @property string $refund_at 退款时间
 * @property string $user_note 用户留言
 * @property int $status 订单状态|{"1":"待支付","2":"待发货","3":"待收货","4":"已收货","5":"已完成","6":"已取消","7":"已关闭"}
 * @property int $pay_status 支付状态|{"1":"待支付","2":"部分支付","3":"已支付","4":"部分退款","5":"已退款","6":"申请退款中","7":"拒绝退款"}
 * @property string $payer_name 支付人姓名
 * @property string $payer_no 支付人身份证号码
 * @property string $payer_mobile 支付人手机号码
 * @property array $payer 实名信息
 * @property string $attach 附加数据
 * @property string $source 订单来源
 * @property int $auto_erp 自动推送ERP
 * @property string $pay_code 支付编码
 * @property int $is_jump 是否跳转到跨进申报系统小程序支付
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class Order extends Model
{
    use OrderTraits, Snowflake;

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'order';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [
        'id', 'shop_id', 'app_id', 'user_id', 'no', 'paid_no', 'merchant_no',
        'transaction_id', 'consignee', 'address', 'mobile', 'prov', 'city',
        'area', 'shipping_at', 'paid_amount', 'total_amount', 'postage_amount',
        'discount_amount', 'time_expire', 'confirm_at', 'complete_at',
        'paid_at', 'refund_at', 'user_note', 'status', 'pay_status',
        'payer_name', 'payer_no', 'payer_mobile', 'payer', 'attach', 'source',
        'created_at', 'updated_at', 'auto_erp', 'pay_code', 'is_jump'
    ];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = [
        'id' => 'string', 'shop_id' => 'integer', 'app_id' => 'integer',
        'user_id' => 'integer', 'status' => 'integer',
        'pay_status' => 'integer', 'payer' => 'array',
        'discount_amount' => 'array', 'paid_amount' => 'decimal:2',
        'created_at' => 'datetime', 'updated_at' => 'datetime',
        'auto_erp' => 'integer', 'is_jump' => 'integer',
    ];

    /**
     * 自动新增
     * @var array|string[]
     */
    public array $insert = [
        'shop_id',
        'no',
        'time_expire'
    ];
}
